package com.auxgroup.hr.front.service.modperson.impl;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModJcxx;
import com.auxgroup.hr.front.dao.domain.PsCModPerPrimary;
import com.auxgroup.hr.front.dao.repository.PsCModJcxxRepository;
import com.auxgroup.hr.front.service.modperson.ModJcxxService;

/** 
 * @author lvliuhao
 * @version 创建时间：180526 
 * 奖惩情况流程信息service
 */
@Service("modJcxxService")
public class ModJcxxServiceImpl implements ModJcxxService {
	private static final Logger logger = LoggerFactory.getLogger(ModJcxxServiceImpl.class);
	
	@Autowired
	private PsCModJcxxRepository PsCModJcxxRepository;


	@Override
	public PsCModJcxx getModJcxx(PsCModPerPrimary modPerPrimary) {
		return PsCModJcxxRepository.findOne(modPerPrimary);
	}


	@Override
	public PsCModJcxx save(PsCModJcxx ModJcxx,UserDTO user) {
		ModJcxx.setHrsRowAddOprid(user.getOprId());
		ModJcxx.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		ModJcxx.setHrsRowUpdOprid(user.getOprId());
		ModJcxx.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		Set<String> ignoreFields = new HashSet<String>(Arrays.asList("cSeqno"));
		ObjectFieldUtils.handleNullValue(ModJcxx,ignoreFields);
		return PsCModJcxxRepository.save(ModJcxx);
	}


	@Override
	public Boolean delete(PsCModPerPrimary modPerPrimary) {
		try {
			PsCModJcxxRepository.delete(modPerPrimary);
		} catch (Exception e) {
			logger.error("delete ModJcxx error: modPerPrimary={}",modPerPrimary,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCModJcxx> getAll(String emplid) {
		PsCModJcxx ModJcxx = new PsCModJcxx();
		ModJcxx.setEmplid(emplid);
		return PsCModJcxxRepository.findAll(Example.of(ModJcxx));
	}


	/* (non-Javadoc)
	 * @see ModJcxxService#getAll(java.lang.String, java.lang.String)
	 */
	@Override
	public List<PsCModJcxx> getAll(String cTransactionNbr, String emplid) {
		PsCModJcxx ModJcxx = new PsCModJcxx();
		ModJcxx.setEmplid(emplid);
		ModJcxx.setcTransactionNbr(cTransactionNbr);
		return PsCModJcxxRepository.findAll(Example.of(ModJcxx));
	}


	
	
	
}
